<template>
    <view class="page">
        <div class="header">
            <div class="flex">
                <div>总资产(元)</div>
                <div @click="bindGoRule()">规则</div>
            </div>
            <div class="flex money">
                <div class="count">{{designerUser?.nowMoney}}</div>
                <div class="flex btns">
                    <div class="tixian" @click="bindTiXian()">提现</div>
                    <div class="tixian chongzhi" @click="bindChongZhi()">充值</div>
                </div>
            </div>
            <div class="flex ai-count" @click="bindGoAIhistory()">
                可用AI设计次数：<span class="count-no"> {{designerUser?.points}}</span>
                <image
                    class="right-icon"
                    src="https://cos.aitshirt.cn/app-icon/%E8%B7%AF%E5%BE%84%20224%402x.png"
                    alt=""
                    mode="aspectFit"
                ></image>
            </div>
            <div class="tixian-list">
                <div class="tx-item">
                    <div class="tx-title">可提现金额(元)</div>
                    <div class="tx-money">{{designerUser?.brokeragePrice}}</div>
<!--                    <image-->
<!--                        class="right-icon"-->
<!--                        src="https://cos.aitshirt.cn/app-icon/%E8%B7%AF%E5%BE%84%20224%402x.png"-->
<!--                        alt=""-->
<!--                        mode="aspectFit"-->
<!--                    ></image>-->
                </div>
                <div class="tx-item">
                    <div class="tx-title">累计提现(元)</div>
                    <div class="tx-money">{{designerUser?.extractCount}}</div>
<!--                    <image-->
<!--                        class="right-icon"-->
<!--                        src="https://cos.aitshirt.cn/app-icon/%E8%B7%AF%E5%BE%84%20224%402x.png"-->
<!--                        alt=""-->
<!--                        mode="aspectFit"-->
<!--                    ></image>-->
                </div>
            </div>
        </div>

      <div class="good-content">
        <div class="tabs" >
            <div class="tab" :class="{active: type == 0}" @click="bindType(0)">收入</div>
            <div class="tab" :class="{active: type == 1}" @click="bindType(1)">支出</div>
            <div class="tab" :class="{active: type == 2}" @click="bindType(2)">提现</div>
            <div class="tab" :class="{active: type == 3}" @click="bindType(3)">充值</div>
        </div>

        <div class="type-0" v-if="type == 0">
          <div class="total">
            <div class="txt">共收入{{hotSellingProductsTotal.totalOrderNum}}笔，合计</div>
            <div class="number">￥{{hotSellingProductsTotal.totalDesignAmount}}</div>
          </div>
          <div class="good-ul" style="display: flex; flex-direction: column; gap: 16rpx">
            <div class="title" v-if="hotSellingProducts?.length">最佳作品</div>
            <template v-for="(item, index) in hotSellingProducts" :key="item?.id">
              <hot-income-item :item="item" :index="index+1"/>
            </template>
          </div>
        </div>

        <div class="filter-tags" v-if="type == 1">
          <view :class="{ active: aiTag === 1 }" class="filter-tag" @click="bindAiTag(1)">全部</view>
          <view :class="{ active: aiTag === 11 }" class="filter-tag" @click="bindAiTag(11)">AI设计费用</view>
          <view :class="{ active: aiTag === 12 }" class="filter-tag" @click="bindAiTag(12)">购买商品</view>
        </div>
        <div class="order-content" style="height: calc(100vh - 100rpx); background: #fff; margin: 0 16rpx;">
          <ScrollList :finished="isFinished" :loading="isLoading" :show-empty="isFinished && !list?.length" style="height: calc(100vh - 100rpx); width: calc(100vw - 32rpx)" @load="load" @refresh="reset">
            <div class="good-ul" style="display: flex; flex-direction: column; gap: 16rpx; margin: 16rpx 0 0;">
              <div class="title" v-if="type === 0 && list?.length">收入记录</div>
              <template v-for="item in list" :key="item?.id">
                <income-item :item="item" v-if="type === 0"/>
                <ai-income-item :item="item" v-if="type === 1" />
                <MmonePayItem :item="item" v-if="type === 2" />
                <MmonePayItem :item="item" v-if="type === 3" />
              </template>
            </div>
          </ScrollList>
        </div>
<!--        <div class="good-ul">-->
<!--            -->
<!--        </div>-->

<!--        <div class="good-ul pay">-->
<!--            <MmonePayItem v-for="item in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" :key="item" />-->
<!--        </div>-->


      </div>
    </view>
</template>

<script setup lang="ts">
import MmonePayItem from "@/components/MmonePayItem.vue";
import { getDesignUser, getObtainPersonalTransactionRecords, likeDesignList } from "@/api/designUser";
import { ref, shallowRef } from "vue";
import { onShow } from "@dcloudio/uni-app";
import ScrollList from "@/components/scroll-list/scroll-list.vue";
import { usePagination } from "@/hooks/usePagination";
import IncomeItem from "@/pages/wallet/mine/components/incomeItem.vue";
import HotIncomeItem from "@/pages/wallet/mine/components/hotIncomeItem.vue";
import AiIncomeItem from "@/pages/wallet/mine/components/aiIncomeItem.vue";
import { useRouter } from "uni-mini-router"
import { getBank } from "@/api/user";
const router = useRouter();

const show = ref(false)
const designerUser = shallowRef<any>({});

function queryDesignUser() {
  getDesignUser().then((res) => {
    designerUser.value = res.data;
  });
}

const hotSellingProducts = shallowRef([]);
const hotSellingProductsTotal = shallowRef({
  totalOrderNum: 0,
  totalDesignAmount: 0
})

const { list, isLoading, load, reset, isFinished } = usePagination(queryProducts);
function queryProducts(page = 1) {
  const typeValue = type.value === 1 ? (aiTag.value) : (type.value);
  const data = {
    page: page,
    type: typeValue,
  };
  return getObtainPersonalTransactionRecords(data).then(res => {
    hotSellingProducts.value = res.data.hotSellingProducts
    hotSellingProductsTotal.value = res.data.hotSellingProductsTotal
    return {
      data: res.data.list,
      total: res.total,
    };
  });
}
const goods = ref([]);
const type = ref(0);
const bindType = (idx) => {
  type.value = idx;
  reset();
};

const aiTag = ref(1);
const bindAiTag = (tag) => {
  aiTag.value = tag;
  reset();
};
const banks = shallowRef({});
onShow(() => {
  queryDesignUser();
  reset();
  getBank().then((res) => {
    banks.value = res.data;
  });
})
const bindTiXian = () => {
  router.push({
    path: '/pages/wallet/cash/cash',
  })

};
const bindChongZhi = () => {
  router.push({
    path: '/pages/wallet/recharge/recharge',
  })
};

const bindGoAIhistory = () => {
  router.push({
    path: '/pages/wallet/aiHostory/aiHostory',
  })
}

const bindGoRule = () => {
  router.push({
    path: '/pages/wallet/rule/rule',
  })
}
</script>

<style scoped lang="scss">
.flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.page {
    background: #f3f7f8;
    padding: 16rpx;
}
.header {
    display: flex;
    flex-direction: column;
    //width: 100%;
    //height: 250rpx;
    background: #ffffff;
    box-shadow: 0rpx 2rpx 4rpx 2rpx rgba(0, 0, 0, 0.08);
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    padding: 32rpx 16rpx;
    .flex {
        font-weight: 400;
        font-size: 28rpx;
        color: #222222;
        &.money {
            margin: 16rpx 0;
        }
    }
    .count {
      height: 90rpx;
      font-weight: bold;
      font-size: 64rpx;
      color: #F25A27;
      line-height: 90rpx;
    }

    .count-no {
      height: 32rpx;
      font-weight: bold;
      font-size: 24rpx;
      color: #222222;
      line-height: 32rpx;
    }
    .btns {
        gap: 16rpx;
        .tixian {
            width: 120rpx;
            height: 48rpx;
            background: #f3f7f8;
            border-radius: 32rpx 32rpx 32rpx 32rpx;
            font-weight: bold;
            font-size: 28rpx;
            color: #222222;
            line-height: 48rpx;
            text-align: center;
            &.chongzhi {
                background: #f25a27;
                color: #ffffff;
            }
        }
    }

    .ai-count {
        gap: 12rpx;
        height: 32rpx;
        font-weight: 400;
        font-size: 24rpx;
        color: #222222;
        line-height: 32rpx;
        justify-content: flex-start;
        padding: 0 0 32rpx;
        .count {
            font-weight: bold;
        }
        .right-icon {
            width: 12rpx;
            height: 20rpx;
        }
    }

    .tixian-list {
      position: relative;
        display: flex;
        align-items: center;
        height: 66rpx;
        gap: 64rpx;
      &:after {
        position: absolute;
        left: 50%;
        content: "";
        width: 0rpx;
        height: 32rpx;
        border: 1rpx solid #E4E4E4;
        transform: translateX(-50%);
      }
      .tx-item {
        width: 50%;
        display: flex;
        align-items: center;
            font-weight: 400;
            font-size: 24rpx;
            color: #222222;
            line-height: 32rpx;
            .tx-title {
            }
            .tx-money {
                font-weight: bold;
              margin: 0 16rpx;
            }
            .right-icon {
                width: 12rpx;
                height: 20rpx;
                margin-left: auto;
            }
        }
    }
}


.good-content {
  background: #FFFFFF;
  border-radius: 16rpx 16rpx 16rpx 16rpx;
  margin: 16rpx 0;
}
.tabs {
  position: sticky;
  top: 0;
  height: 86rpx;
  display: flex;
  padding: 0 62rpx;
  border: 1rpx solid #E4E4E4;
  justify-content: space-between;
  align-items: center;
  background: #ffffff;
  z-index: 99;
  .tab {
    font-weight: 400;
    font-size: 28rpx;
    color: #6F6F6F;
    line-height: 38rpx;
    &.active {
      position: relative;
      font-weight: bold;
      &:after {
        position: absolute;
        content: "";
        bottom: -22rpx;
        left: 0;
        width: 100%;
        height: 4rpx;
        background: #F25A27;
        border-radius: 4rpx 4rpx 4rpx 4rpx;
      }
    }
  }
}

.good-ul {
  //width: 686rpx;
  //height: 468rpx;
  background: #FFFFFF;
  box-shadow: 0rpx 2rpx 4rpx 2rpx rgba(0,0,0,0.08);
  border-radius: 16rpx 16rpx 16rpx 16rpx;
  margin: 0 16rpx;
  .title {
    font-weight: bold;
    font-size: 28rpx;
    color: #222222;
    margin: 32rpx 16rpx 0;
  }
}


.pay {
  .pay-li {
    height: 120rpx;
    .image-detail {
      .image-content {
        image {
          width: 72rpx;
          height: 72rpx;
        }
      }
    }
  }
}

.type-0 {
  .total {
    height: 80rpx;
    background: #F3F7F8;
    border-radius: 8rpx 8rpx 8rpx 8rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16rpx ;
    margin: 16rpx;
    .txt {

      font-weight: 400;
      font-size: 24rpx;
      color: #222222;
    }
    .number {

      font-weight: bold;
      font-size: 28rpx;
      color: #F25A27;
      line-height: 38rpx;
    }
  }
}

.filter-tags {
  //position: sticky;
  //top: 100rpx;
  display: flex;
  align-items: center;
  gap: 16rpx;
  margin: 16rpx;
  z-index: 9;

  .filter-tag {
    width: 112rpx;
    height: 48rpx;
    background: #ffffff;
    border-radius: 8rpx 8rpx 8rpx 8rpx;
    font-weight: 400;
    font-size: 24rpx;
    color: #222222;
    line-height: 48rpx;
    text-align: center;

    &.active {
      background: #f25a27;
      color: #ffffff;
    }
  }
}
</style>
